home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1996, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
-
- /* shear.c - open a window and clear the background.
- * glutMainLoop() calls drawScene whenever the window needs
- * to be updated.
- */
- #include <GL/gl.h>
- #include <GL/glu.h>
- #include <GL/glut.h>
-
- /* Function Prototypes */
- GLvoid initgfx( );
- GLvoid reshape( GLsizei, GLsizei );
- GLvoid drawScene( GLvoid );
- GLvoid keyboard( GLubyte, GLint, GLint );
-
- /* Global Definitions */
-
- #define KEY_ESC 27 /* ascii value for the escape key */
-
- /* Global Variables */
-
- GLboolean shearFlag = GL_FALSE;
-
- void
- main( int argc, char *argv[] )
- {
- GLsizei width, height;
- glutInit(&argc, argv);
-
- width = glutGet(GLUT_SCREEN_WIDTH);
- height = glutGet(GLUT_SCREEN_HEIGHT);
- glutInitWindowPosition( width / 4, height / 4);
- glutInitWindowSize( width / 2, height / 2 );
- glutInitDisplayMode( GLUT_RGBA );
- glutCreateWindow( argv[0] );
-
- initgfx( );
-
- glutReshapeFunc( reshape );
- glutKeyboardFunc( keyboard );
- glutDisplayFunc( drawScene );
- glutMainLoop();
- }
-
- GLvoid
- initgfx()
- {
- /* set clear color to magenta */
- glClearColor( 0.0, 0.0, 1.0, 1.0 );
- }
-
- GLvoid
- reshape( GLsizei w, GLsizei h )
- {
- GLfloat aspect = (GLfloat)w / (GLfloat)h;
- glViewport(0, 0, w, h);
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluOrtho2D( -3.0*aspect, 3.0*aspect, -3.0, 3.0);
- glMatrixMode(GL_MODELVIEW);
- }
-
- GLvoid
- renderBitmapString( void *font, char *string )
- {
- int i;
- int len = (int) strlen(string);
- for (i = 0; i < len; i++) {
- glutBitmapCharacter(font, string[i]);
- }
- }
-
-
- GLvoid
- keyboard( GLubyte key, GLint x, GLint y )
- {
- switch (key) {
- case 's': /* toggle shear mode */
- shearFlag = !shearFlag;
- glutPostRedisplay();
- break;
- case KEY_ESC: /* Exit whenever the Escape key is pressed */
- exit(0);
- }
- }
-
- GLvoid
- drawScene( GLvoid )
- {
- glClear( GL_COLOR_BUFFER_BIT );
-
- glPushMatrix(); {
-
- GLfloat shearMatrix[] = { 1, 0, 0, 0,
- 1.5, 1, 0, 0,
- 0, 0, 1, 0,
- 0, 0, 0, 1 };
-
- glTranslatef(1.0, -0.5, 0.0);
- XYaxes();
-
- if (shearFlag)
- glMultMatrixf(shearMatrix);
-
- glColor3f(1.0, 0.5, 0.0);
- glRectf(-1.0, -1.0, 1.0, 1.0);
-
- } glPopMatrix();
-
- glMatrixMode(GL_PROJECTION);
- glPushMatrix(); {
- GLsizei width, height;
- char str[100];
-
- glLoadIdentity();
- width = glutGet(GLUT_WINDOW_WIDTH);
- height = glutGet(GLUT_WINDOW_HEIGHT);
- gluOrtho2D( 0.0, (GLfloat)width, 0.0, (GLfloat)height);
-
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix(); {
- glLoadIdentity();
- glColor3f(0.5, 0.5, 0.5);
- glRasterPos2f(5.0, 25.0);
- renderBitmapString(GLUT_BITMAP_8_BY_13,
- "Hit 's' to toggle shear");
-
- if (shearFlag)
- sprintf(str, "Shearing...");
- else
- sprintf(str, "Not shearing...");
- glRasterPos2f(5.0, 5.0);
- renderBitmapString(GLUT_BITMAP_8_BY_13, str);
- } glPopMatrix();
-
- glMatrixMode(GL_PROJECTION);
- } glPopMatrix();
-
- checkError( "drawScene" );
- glFlush();
- }
-